Next | Prev | Up | Top | Contents | Index

Device Representation

The IRIX record of a file's existence is sometimes called an inode. The device special files consist of inodes only, with no associated data. The fields of the inode are used to encode the following critical information about a device:

FilenamePrograms use the name of a device file to open the device using open().
Permissions,
Owner ID,
Group ID
The file access permissions, owner ID, and group ID of a device file establish which users can read and which can write to that device.
Block or
Character
A device file belongs to one of two classes, block or character, visible as the first letter of an ls -l display.
Major device numberA code for the device driver that controls this device.
Minor device numberA code specifying the unit or position of this device under its controller.

All this information is visible in a display produced by ls -l. The major and minor numbers are shown in the column used for file size for regular files. Examine the output of a command such as

ls -l /dev/* | more

A device special file can be used the same as a regular file in most IRIX commands; for example, a device file can be the target of a symbolic link, the destination of redirected input or output, and so on.


Block Versus Character

IRIX supports two classes of device. A block device such as a disk drive transfers data in fixed size blocks between the device and memory, and usually has some ability to reposition the medium so as to read or write the same data again. The driver for a block device typically has to manage buffering, and may schedule I/O operations in a different sequence than they are requested.

A character device such as a printer accepts or returns data as a stream of bytes, and usually acts as a sink or source of data--the medium cannot be repositioned and read again. The driver for a character device typically transfers data as soon as it is requested and completes one operation before accepting another request. Character devices are also called raw devices, because their input is not buffered.


Major Device Number

The major device number recorded in the device special inode selects the device driver to service this device. When a device is opened, IRIX selects the driver to handle the device based on the major device number. Each device driver supports one or more specific major numbers. There are two unrelated ranges of major numbers, one for character device drivers and one for block device drivers.

The possible major numbers are declared and given names in the file sys/major.h. When you create a new kernel-level device driver you must choose a major number for it--a number not used by any other driver. Numbers 60-79 are not used by Silicon Graphics. (See "Selecting a Major Number".)

In IRIX releases through 5.2 (and 6.0.x, which is based on 5.2), major numbers were limited to the range 0 through 254. Beginning with releases 5.3 and 6.1, the IRIX inode structure permits major numbers to have up to 14 bits of precision. However, major numbers are currently restricted to at most 9 bits to conserve kernel data space.

In order to use this limit symbolically, use the name L_MAXMAJ defined in sys/sysmacros.h. When you declare a variable for a major device number in a program, use type major_t declared in sys/types.h.

Normally a device driver services only one major number. However, it is possible to designate the same device driver to service more than one major number. In this case, the driver may need to discover the major number at execution time. The getemajor() function returns the number in use for a given request (see the getemajor(D3) reference page).


Minor Device Number

The minor device number is passed to the device driver as an argument when the driver is called. (The major and minor numbers are passed together in a long integer called a dev_t.) The minor device number is interpreted only by the device driver, so it can be a simple logical unit number, or it can contain multiple, encoded bit fields. For example:

The IRIX inode structure permits minor numbers to have up to 18 bits of precision. In order to use this limit symbolically, use the name L_MAXMIN defined in sys/sysmacros.h. When you declare a variable for a minor device number in a program, use type minor_t declared in sys/types.h.

With STREAMS drivers, the minor device number can be chosen arbitrarily during a CLONE open--see "Support for CLONE Drivers".


Next | Prev | Up | Top | Contents | Index